
<#assign className=table.className>
<#assign classNameFirstLower=className?uncap_first>
<#assign classNameLowerCase=className?lower_case>
<#assign pkJavaType=table.idColumn.javaType>

package ${basepackage}.controller;

import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;

import java.text.SimpleDateFormat;
import java.util.Date;

import javacommon.base.BaseRestSpringController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Validator;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource;
import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.web.scope.Flash;


@Controller
@RequestMapping("/${classNameLowerCase}")
public class ${className}Controller extends SpringMVCBaseController{
        //默认多列排序,example: username desc,createTime asc
        protected static final String DEFAULT_SORT_COLUMNS=null;

        public static final String PAGE_PATH_PREFIX = SysConstants.BACK_PAGE_DIR_PATH + "/${classNameFirstLower}";

        @Resource
        private ${className}Service ${classNameFirstLower}Service;

        private final String LIST_ACTION="redirect:list.do";


        /** binder用于bean属性的设置 */
        @InitBinder
        public void initBinder(WebDataBinder binder){
                binder.registerCustomEditor(Date.class,new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true));
                }

        /** 列表 */
        @RequestMapping("/list")
        public String list(){
                return this.PAGE_PATH_PREFIX + "/list";
        }

        /** 查询 */
        @RequestMapping("/search")
        @ResponseBody
        public String search(ModelMap model, ${className} ${classNameFirstLower},int start,int length){
                int page = start/length+1;
                int pageSize = length;
                /*
                if (${classNameFirstLower} != null && ${classNameFirstLower}.getName() != null) {
                    sysRole.setName(transcodingIfGet(sysRole.getName()));
                }
                */
                JsonConfig jsonConfig = new JsonConfig();

                <#assign excludes = "">
                <#list table.exportedKeys.associatedTables?values as foreignKey>
                <#assign fkSqlTable = foreignKey.sqlTable>
                <#assign fkTable    = fkSqlTable.className>
                <#assign fkPojoClass = fkSqlTable.className>
                <#assign fkPojoClassVar = fkPojoClass?uncap_first>
                <#assign excludes = '"' + fkPojoClassVar + 's",'>
                </#list>
                jsonConfig.setExcludes(new String[]{${excludes + '"@@@"'}});

                return responseJSON(jsonConfig, ${classNameFirstLower}Service.get${className}List(${classNameFirstLower}, page, pageSize));
        }
        <#--
        *//** 显示 *//*
        @RequestMapping(value = "/{id}")
        public String show(ModelMap model,@PathVariable ${pkJavaType}id)throws Exception{
                ${className}${classNameFirstLower}=(${className})${classNameFirstLower}Manager.getById(id);
                model.addAttribute("${classNameFirstLower}",${classNameFirstLower});
                return"/${classNameLowerCase}/show";
                }*/
        -->
        @RequestMapping("/addUI")
        public String addUI() {
                return this.PAGE_PATH_PREFIX + "/add";
        }

        @RequestMapping("/add")
        @ModuleFunction("角色添加")
        public String add(${className} ${classNameFirstLower}) {
                ${classNameFirstLower}Service.addNew${className}(${classNameFirstLower});
                return this.LIST_ACTION;
        }

        @RequestMapping("/edit")
        @ModuleFunction("角色修改")
        public String edit(${className} ${classNameFirstLower}) {
                ${classNameFirstLower}Service.edit${className}(${classNameFirstLower});
                return this.LIST_ACTION;
        }

        @RequestMapping("/editUI")
        public String editUI(Long ${classNameFirstLower}Id) {
                setRequestAttribute("${classNameFirstLower}", ${classNameFirstLower}Service.get(${className}.class, ${classNameFirstLower}Id));
                return this.PAGE_PATH_PREFIX + "/edit";
                }

        /** 删除 *//*
        @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
        public String delete(ModelMap model,@PathVariable ${pkJavaType}id){
                ${classNameFirstLower}Manager.removeById(id);
                Flash.current().success(DELETE_SUCCESS);
                return LIST_ACTION;
                }

        *//** 批量删除 *//*
        @RequestMapping(method = RequestMethod.DELETE)
        public String batchDelete(ModelMap model,@RequestParam("items")${pkJavaType}[]items){
                for(int i=0;i<items.length;i++){
                ${classNameFirstLower}Manager.removeById(items[i]);
                }
                Flash.current().success(DELETE_SUCCESS);
                return LIST_ACTION;
                }
*/
}

